package com.example.blogother.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xpd.blog.bean.ResultMessage;

public class MessageUtil {
    public static String getMessage(boolean isSystem,String fromName,Object message){

        try {
            ResultMessage resultMessage=new ResultMessage();
            resultMessage.setMessage(message);
            resultMessage.setSystem(isSystem);
            if(fromName!=null){
                resultMessage.setFromName(fromName);
            }
            ObjectMapper mapper=new ObjectMapper();
            return mapper.writeValueAsString(resultMessage);
        } catch (JsonProcessingException e) {
           e.printStackTrace();
        }
        return null;

    }
}
